"""
@File    ：verification_code.py
@Author  ：ixiaodu
@Date    ：2024/12/6
@Desc    ：
"""
from PIL import Image
import numpy as np
import cv2
import ddddocr


def get_verification_code(path):

    image =Image.open(path)

    shapes = []
    for i in range(1,4):
        image.seek(i)
        image.save(f'./files/{i}.png')
        shapes.append(np.array(image))

    result = np.subtract(shapes[0], shapes[2])
    result2 = np.subtract(shapes[0], shapes[1])
    result3 = np.subtract(shapes[1], shapes[2])
    cv2.imwrite("result.png", shapes[0] + result+result2+result3)


    ocr = ddddocr.DdddOcr(show_ad=False)
    with open('./files/result.png', 'rb') as f:
        img_bytes = f.read()
    res = ocr.classification(img_bytes)
    return res


if __name__ == '__main__':
    get_verification_code(r"/files/captcha.gif")
